package com.example.web;

import com.example.domain.Student;
import com.example.feign.FeignProviderMethods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/hystrix")
public class StudentController {

    @Autowired
    private FeignProviderMethods feignProviderMethods;

    @RequestMapping("/findAll")
    public List<Student> findAllStudent(){
        return feignProviderMethods.findAllStudent();
    }

    @GetMapping("/findById/{id}")
    public Student findStudentById(@PathVariable("id") Long id){
        return feignProviderMethods.findStudentById(id);
    }

    @PostMapping("/save")
    public Student saveStudent(@RequestBody Student student){
        return feignProviderMethods.saveStudent(student);
    }

    @PutMapping("/update")
    public Student updateStudent(@RequestBody Student student){
        return feignProviderMethods.updateStudent(student);
    }

    @DeleteMapping("/deleteById/{id}")
    public Boolean deleteStudentById(@PathVariable("id") Long id){
        return feignProviderMethods.deleteStudentById(id);
    }

    @RequestMapping("/index")
    public String index(){
        return feignProviderMethods.index();
    }
}
